package com.study.example.singleton;

import com.study.annoations.Recommend;
import com.study.annoations.ThreadSafety;
import com.study.annoations.ThreadUnsafe;

/**
 * @author 贺瑞杰
 * @version V1.0
 * @date 2018-06-17 1:11
 * @description 枚举单例模式  最安全的
 */
@ThreadSafety
@Recommend
public class SingletonExample {

	/**
	 * 私有构造函数
	 */
	private SingletonExample(){

	}

	public static SingletonExample getSingletonExample() {
		return Singleton.INSTANCE.getSingleton();
	}

	private enum Singleton{
		INSTANCE;

		private SingletonExample singleton;

		/**
		 * JVM保证这个方法决对只调用一次
		 */
		Singleton(){
			singleton = new SingletonExample();
		}

		public SingletonExample getSingleton() {
			return singleton;
		}
	}

}
